<template>
  <div class="index">
    <nav-bar></nav-bar>
    <div class="mid-width">
      <el-row><h3>&nbsp;</h3></el-row>
      <!-- <el-row>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/index' }">&nbsp;&nbsp;<i class="el-icon-house"></i>&nbsp;&nbsp;首页</el-breadcrumb-item>
                <el-breadcrumb-item><a href="/">{{this.$route.query.typeId | nameTit}}</a></el-breadcrumb-item>
            </el-breadcrumb>
        </el-row> -->
      <el-row>
        <entry :list=tableData ></entry>
      </el-row>
      <el-row>
            <el-pagination
                    @current-change="handleCurrentChange"
                    background
                    :current-page="curPage"
                    layout="prev, pager, next"
                    :total="pageTotal">
            </el-pagination>
      </el-row>
    </div>

    <footer-bar></footer-bar>
  </div>
</template>

<script>
  import {apiData} from '../interface/api';
  import navBar from '../components/navbar'
  import entry from '../components/entry'
  import footerBar from '../components/footer'
  export default {
    name: 'index',
    data(){
        return {
            tableData: [],
            pageTotal:null,
            curPage:1,
            pageSize:10,
            typeId:this.$route.query.typeId,
        }
    },
    methods:{
      async newList(method, url, obj){
          const res = await apiData.policyList(method, url, obj)
          if(res.data.code===200){
              console.log(res)
              this.tableData = res.data.list
              this.pageTotal = res.data.totals
          }
      },
      handleCurrentChange(Page){
          this.curPage = Page;
          //console.log(this.curPage)  //点击第几页
          this.newList("post", `/web/newsList?pageNum=${this.curPage}&pageSize=${this.pageSize}`, {typeId:this.typeId})
      }
    },
    mounted() {
      this.newList("post", `/web/newsList?pageNum=${this.curPage}&pageSize=${this.pageSize}`, {typeId:this.typeId})
    },
    watch:{
      // "$route"(val,old){
      //     if(old!==val){
      //         this.typeId = val.query.typeId;
      //         this.newList("post", `/web/newsList?pageNum=${this.curPage}&pageSize=${this.pageSize}`, {typeId:this.typeId})
      //     }

      // }
    },
    filters:{
      // nameTit(id){
      //     let pageTit =1;
      //     switch (id){
      //         case 1:
      //             pageTit = "政策法规";
      //                 break;
      //         case 2:
      //             pageTit = "通知公告";
      //             break;
      //         case 3:
      //             pageTit = "文件下载";
      //             break;
      //     }
      //     return pageTit
      // },
    },
    components: {
      navBar , entry, footerBar
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
  .index {
    height: 100%;
  .el-pagination{
      margin-top: 20px;
  }
  }

</style>
